/*
 * CStats.java
 *
 * Copyright (c) 2009 Giles Millward (Manigra). All rights reserved.
 *
 * This file is part of JRogueDPS.
 *
 * JRogueDPS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JRogueDPS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with JRogueDPS.  If not, see <http://www.gnu.org/licenses/>.
 */

package geardatabase;

import org.dom4j.Element;
import org.dom4j.Node;

/**
 *
 * @author Mani
 */
public class CStats {
    public int m_strength = 0;
    public int m_attackPower = 0;
    public int m_agility = 0;
    public int m_stamina = 0;
    public int m_hitRating = 0;
    public int m_critRating = 0;
    public int m_expertiseRating = 0;
    public int m_armorPenRating = 0;
    public int m_hasteRating = 0;

    public CStats ()
    {
        return;
    }
    
    public CStats (String p_statsString)
    {
        // Remove spaces
        p_statsString = p_statsString.replaceAll(" ", "");
        String l_tokens[] = p_statsString.split(",");
        for (int i = 0; i < l_tokens.length; i++)
        {
            String l_keyValue[] = l_tokens[i].split("=");
            String l_keyLower = l_keyValue[0].toLowerCase();
            if (l_keyLower.equals("strength"))
            {
                m_strength += Integer.parseInt(l_keyValue[1]);
            } else if (l_keyLower.equals("attackpower"))
            {
                m_attackPower += Integer.parseInt(l_keyValue[1]);
            } else if (l_keyLower.equals("agility"))
            {
                m_agility += Integer.parseInt(l_keyValue[1]);
            } else if (l_keyLower.equals("stamina"))
            {
                m_stamina += Integer.parseInt(l_keyValue[1]);
            } else if (l_keyLower.equals("hitrating"))
            {
                m_hitRating += Integer.parseInt(l_keyValue[1]);
            } else if (l_keyLower.equals("critrating"))
            {
                m_critRating += Integer.parseInt(l_keyValue[1]);
            } else if (l_keyLower.equals("expertiserating"))
            {
                m_expertiseRating += Integer.parseInt(l_keyValue[1]);
            } else if (l_keyLower.equals("armorpenrating"))
            {
                m_armorPenRating += Integer.parseInt(l_keyValue[1]);
            } else if (l_keyLower.equals("hasterating"))
            {
                m_hasteRating += Integer.parseInt(l_keyValue[1]);
            } 
        }
    }
    public String getNonZeroStatsString()
    {
        String l_string = "";
        if (m_strength != 0)
        {
            l_string += " Str +" + m_strength;
        }

        if (m_attackPower != 0)
        {
            l_string += " Atk +" + m_attackPower;
        }

        if (m_agility != 0)
        {
            l_string += " Agi +" + m_agility;
        }

        if (m_stamina != 0)
        {
            l_string += " Sta +" + m_stamina;
        }

        if (m_hitRating != 0)
        {
            l_string += " Hit +" + m_hitRating;
        }

        if (m_critRating != 0)
        {
            l_string += " Crit +" + m_critRating;
        }

        if (m_expertiseRating != 0)
        {
            l_string += " Exp +" + m_expertiseRating;
        }

        if (m_armorPenRating != 0)
        {
            l_string += " ArP +" + m_armorPenRating;
        }

        if (m_hasteRating != 0)
        {
            l_string += " Hst +" + m_hasteRating;
        }
        
        return l_string;
    }
    // <editor-fold defaultstate="collapsed" desc="Getters/Setters">
    /**
     * @return the m_strength
     */
    final public int getStrength() {
        return m_strength;
    }

    /**
     * @param m_strength the m_strength to set
     */
    final public void addStrength(int m_strength) {
        this.setStrength(this.m_strength + m_strength);
    }

    /**
     * @return the m_attackPower
     */
    final public int getAttackPower() {
        return m_attackPower;
    }

    /**
     * @param m_attackPower the m_attackPower to set
     */
    final public void addAttackPower(int m_attackPower) {
        this.setAttackPower(this.m_attackPower + m_attackPower);
    }

    /**
     * @return the m_agility
     */
    final public int getAgility() {
        return m_agility;
    }

    /**
     * @param m_agility the m_agility to set
     */
    final public void addAgility(int m_agility) {
        this.setAgility(this.m_agility + m_agility);
    }

    /**
     * @return the m_stamina
     */
    final public int getStamina() {
        return m_stamina;
    }

    /**
     * @param m_stamina the m_stamina to set
     */
    final public void addStamina(int m_stamina) {
        this.setStamina(this.m_stamina + m_stamina);
    }

    /**
     * @return the m_hitRating
     */
    final public int getHitRating() {
        return m_hitRating;
    }

    /**
     * @param m_hitRating the m_hitRating to set
     */
    final public void addHitRating(int m_hitRating) {
        this.setHitRating(this.m_hitRating + m_hitRating);
    }

    /**
     * @return the m_critRating
     */
    final public int getCritRating() {
        return m_critRating;
    }

    /**
     * @param m_critRating the m_critRating to set
     */
    final public void addCritRating(int m_critRating) {
        this.setCritRating(this.m_critRating + m_critRating);
    }

    /**
     * @return the m_expertiseRating
     */
    final public int getExpertiseRating() {
        return m_expertiseRating;
    }

    /**
     * @param m_expertiseRating the m_expertiseRating to set
     */
    final public void addExpertiseRating(int m_expertiseRating) {
        this.setExpertiseRating(this.m_expertiseRating + m_expertiseRating);
    }

    /**
     * @return the m_armorPenRating
     */
    final public int getArmorPenRating() {
        return m_armorPenRating;
    }

    /**
     * @param m_armorPenRating the m_armorPenRating to set
     */
    final public void addArmorPenRating(int m_armorPenRating) {
        this.setArmorPenRating(this.m_armorPenRating + m_armorPenRating);
    }

    /**
     * @return the m_hasteRating
     */
    final public int getHasteRating() {
        return m_hasteRating;
    }

    /**
     * @param m_hasteRating the m_hasteRating to set
     */
    final public void addHasteRating(int m_hasteRating) {
        this.setHasteRating(this.m_hasteRating + m_hasteRating);
    }

    // </editor-fold>

    public void addXMLData(Element p_stats)
    {
        // Add item id
        p_stats.addAttribute("str", String.valueOf(m_strength)).
                addAttribute("atk", String.valueOf(m_attackPower)).
                addAttribute("agi", String.valueOf(m_agility)).
                addAttribute("sta", String.valueOf(m_stamina)).
                addAttribute("hit", String.valueOf(m_hitRating)).
                addAttribute("crit", String.valueOf(m_critRating)).
                addAttribute("exp", String.valueOf(m_expertiseRating)).
                addAttribute("arp", String.valueOf(m_armorPenRating)).
                addAttribute("hst", String.valueOf(m_hasteRating));
    }

    public void parseXML(Node p_node)
    {
        setStrength(Integer.parseInt(p_node.valueOf("@str")));
        setAttackPower(Integer.parseInt(p_node.valueOf("@atk")));
        setAgility(Integer.parseInt(p_node.valueOf("@agi")));
        setStamina(Integer.parseInt(p_node.valueOf("@sta")));
        setHitRating(Integer.parseInt(p_node.valueOf("@hit")));
        setCritRating(Integer.parseInt(p_node.valueOf("@crit")));
        setExpertiseRating(Integer.parseInt(p_node.valueOf("@exp")));
        setArmorPenRating(Integer.parseInt(p_node.valueOf("@arp")));
        setHasteRating(Integer.parseInt(p_node.valueOf("@hst")));
    }

    public void showData()
    {
        System.out.println("str:" + m_strength + " atk:" + m_attackPower + " agi:" + m_agility +
                " sta:" + m_stamina + " hitR:" + m_hitRating + " critR" + m_critRating + " exp:" + m_expertiseRating +
                " arp:" + m_armorPenRating + " haste:" + m_hasteRating);
    }

    public void add(CStats p_addStats)
    {
        this.setAgility(this.m_agility + p_addStats.m_agility);
        this.setArmorPenRating(this.m_armorPenRating + p_addStats.m_armorPenRating);
        this.setAttackPower(this.m_attackPower + p_addStats.m_attackPower);
        this.setCritRating(this.m_critRating + p_addStats.m_critRating);
        this.setExpertiseRating(this.m_expertiseRating + p_addStats.m_expertiseRating);
        this.setHasteRating(this.m_hasteRating + p_addStats.m_hasteRating);
        this.setHitRating(this.m_hitRating + p_addStats.m_hitRating);
        this.setStamina(this.m_stamina + p_addStats.m_stamina);
        this.setStrength(this.m_strength + p_addStats.m_strength);
    }

    public void subtract(CStats p_subtractStats)
    {
        this.setAgility(this.m_agility - p_subtractStats.m_agility);
        this.setArmorPenRating(this.m_armorPenRating - p_subtractStats.m_armorPenRating);
        this.setAttackPower(this.m_attackPower - p_subtractStats.m_attackPower);
        this.setCritRating(this.m_critRating - p_subtractStats.m_critRating);
        this.setExpertiseRating(this.m_expertiseRating - p_subtractStats.m_expertiseRating);
        this.setHasteRating(this.m_hasteRating - p_subtractStats.m_hasteRating);
        this.setHitRating(this.m_hitRating - p_subtractStats.m_hitRating);
        this.setStamina(this.m_stamina - p_subtractStats.m_stamina);
        this.setStrength(this.m_strength - p_subtractStats.m_strength);
    }

    public void clone(CStats p_stats)
    {
        this.setAgility(p_stats.m_agility);
        this.setArmorPenRating(p_stats.m_armorPenRating);
        this.setAttackPower(p_stats.m_attackPower);
        this.setCritRating(p_stats.m_critRating);
        this.setExpertiseRating(p_stats.m_expertiseRating);
        this.setHasteRating(p_stats.m_hasteRating);
        this.setHitRating(p_stats.m_hitRating);
        this.setStamina(p_stats.m_stamina);
        this.setStrength(p_stats.m_strength);
    }
    /**
     * @param m_strength the m_strength to set
     */
    final public void setStrength(int m_strength) {
        this.m_strength = m_strength;
    }

    /**
     * @param m_attackPower the m_attackPower to set
     */
    final public void setAttackPower(int m_attackPower) {
        this.m_attackPower = m_attackPower;
    }

    /**
     * @param m_agility the m_agility to set
     */
    final public void setAgility(int m_agility) {
        this.m_agility = m_agility;
    }

    /**
     * @param m_stamina the m_stamina to set
     */
    final public void setStamina(int m_stamina) {
        this.m_stamina = m_stamina;
    }

    /**
     * @param m_hitRating the m_hitRating to set
     */
    final public void setHitRating(int m_hitRating) {
        this.m_hitRating = m_hitRating;
    }

    /**
     * @param m_critRating the m_critRating to set
     */
    final public void setCritRating(int m_critRating) {
        this.m_critRating = m_critRating;
    }

    /**
     * @param m_expertiseRating the m_expertiseRating to set
     */
    final public void setExpertiseRating(int m_expertiseRating) {
        this.m_expertiseRating = m_expertiseRating;
    }

    /**
     * @param m_armorPenRating the m_armorPenRating to set
     */
    final public void setArmorPenRating(int m_armorPenRating) {
        this.m_armorPenRating = m_armorPenRating;
    }

    /**
     * @param m_hasteRating the m_hasteRating to set
     */
    final public void setHasteRating(int m_hasteRating) {
        this.m_hasteRating = m_hasteRating;
    }

}
